package linkedlist.test19;

import listbyorder.utils.ListNode;

/**
 * 删除链表的倒数第N个节点
 *
 * @author code_yc
 * @version 1.0
 * @date 2020/7/14 13:46
 */
public class Solution1 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummy = new ListNode(-1);
        dummy.next = head;
        ListNode s = dummy;
        ListNode f = dummy;
        while (n-- != 0) {
            f = f.next;
        }
        while (f.next != null) {
            f = f.next;
            s = s.next;
        }
        s.next = s.next.next;
        return dummy.next;
    }
}
